// common/page/article/article.js
let app =getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      theme: app.globalData.theme,
      fromPage:options.fromPage
    });
    app.setNavigationBarColor();
    if (options.fromPage =="noticePage"){
      this.setData({
        id: options.id
      });
      this.articleNoticeDetail();
    } else if (options.fromPage == "operationManualPage"){
      this.operationManualDetail();
    } else if (options.fromPage =="shopsPage"){
      this.setData({
        id: options.id
      });
      this.shopsDetail();
    } else if (options.fromPage == "businessPage"){
      this.setData({
        id: options.id
      });
      this.businessDetail();
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  /**
   * 获取通知公告
   */
  articleNoticeDetail: function () {
    app.wxGetRequest("/app-community/v1/notice", {id:this.data.id}).then(result => {
      result.data["content"] = result.data.content.replace(/http:\/\/183.230.93.87:81\//g, app.globalData.showImage).replace(/http:\/\/192.168.211.9\//g, app.globalData.showImage);
      this.setData({
        result: result.data,
      });
    });
  },
  /**
   * 操作手册
   */
  operationManualDetail:function(){
    const accountInfo = wx.getAccountInfoSync();
    app.wxGetRequest("/app-community/v1/greet", { number: accountInfo.miniProgram.appId,type:2 }).then(result => {
      result.data.records.forEach((item, index) => {
        if (item.type == 2 && item.is_state) {
          item["content"] = item.content.replace(/http:\/\/183.230.93.87:81\//g, app.globalData.showImage).replace(/http:\/\/192.168.211.9\//g, app.globalData.showImage);
          this.setData({
            result: item,
          });
        }
      });
    });
  },
  /**
   * 店铺详情
   */
  shopsDetail: function () {
    const accountInfo = wx.getAccountInfoSync();
    app.wxGetRequest("/app-community/v1/shop", { id: this.data.id}).then(result => {
      this.setData({
        result: result.data,
      });
    });
  },
  /**
   * 办事指南详情
   */
  businessDetail:function(){
    app.wxGetRequest("/app-community/v1/article", { id: this.data.id }).then(result => {
      result.data["content"] = result.data.content.replace(/http:\/\/183.230.93.87:81\//g, app.globalData.showImage).replace(/http:\/\/192.168.211.9\//g, app.globalData.showImage);
      this.setData({
        result: result.data,
      });
    });
  }
})